package com.yanyeori.springtransaction.dao.impl;

import com.yanyeori.springtransaction.dao.BankDao;
import com.yanyeori.springtransaction.entity.Bank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author chenkuan
 * @desc
 * @date 2021/3/10 010 19:03
 */
@Repository
public class BankDaoImpl implements BankDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Bank select(Integer id) {
        if (id == null) {
            throw new NullPointerException("id不能为null");
        }
        Bank bank = jdbcTemplate.queryForObject("select * from t_bank where id = ?", new BeanPropertyRowMapper<>(Bank.class), id);
        return bank;
    }

    @Override
    public void add(Bank bank) {
        if (bank == null) {
            throw new NullPointerException("user不能为null");
        }
    }

    @Override
    public void updateNameById(Bank bank) {
        if (bank == null) {
            throw new NullPointerException("user不能为null");
        }
        int update = jdbcTemplate.update("update t_bank set bank_name = ? where id = ?", bank.getBankName(), bank.getId());
        System.out.println("update=" + update);
    }

    @Override
    public void delete(Integer id) {
        if (id == null) {
            throw new NullPointerException("id不能为null");
        }
    }
}
